/**
 * Welcome to https://waylau.com
 */
package httpserver;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.HttpServerExpectContinueHandler;

/**
 * HTTP Server ChannelInitializer.
 * NettyHTTP编解码器
 * 
 * @since 1.0.0 2019年12月26日
 * @author <a href="https://waylau.com">Way Lau</a>
 */
public class HttpServerChannelInitializer extends ChannelInitializer<SocketChannel> {

	public HttpServerChannelInitializer() {

	}

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		/* 或者使用HttpRequestDecoder & HttpResponseEncoder */
		ch.pipeline().addLast("codec", new HttpServerCodec());

		/* 在处理POST消息体时需要加上 */
		ch.pipeline().addLast("aggregator", new HttpObjectAggregator(1048576));//1024*1024=1048576
		ch.pipeline().addLast("expectcontinuehandler", new HttpServerExpectContinueHandler());//100-continue协议处理
		ch.pipeline().addLast("serverHandler", new HttpServerHandler());
	}

}
